
/***********************************************************************
 * Save class
 * 
 * Implements the 'save' command
 *
 * Signature:
 *  public static Orbit create ();
 *  public String name ();
 *  public boolean execute (String[] arguments);
 ***********************************************************************/

public class Save extends Command {

  protected Save () {
    super("save");
  }

  public static Save create () {
    return new Save();
  }

  private boolean saveGameState(String filename) {
    String gameState = "";
    Map currentMap = SpaceGame.map();
    gameState = "[" + currentMap.size().xPos() + "," 
      + currentMap.size().yPos() + ","
      + SpaceGame.clock().currentTime() + ","
      + SpaceGame.me().jsonString();
    FuncIterator<Artifact> arts = currentMap.getFuncIterator();
    while(arts.hasElement()) {
      gameState += "," + arts.current().jsonString();
      arts = arts.advance();
    }
    gameState += "]";

    System.out.println(gameState);
    return true;
  }
  
  private boolean fileExists(String str) {
    // TODO: Implement this method
    return true;
  }

  public boolean execute (String[] args) {
    if(fileExists(args[0])) {
      return saveGameState(args[0]);
    } else {
      System.out.println("invalid filename, game was not saved: " + args[0]);
      return false;
    }
  }

}